Plex.Lib.JS.load('UI.Button.Small_Text');
Plex.Lib.JS.load('Com.DND');
Plex.Lib.CSS.load('UI.Page.Popup');



Plex.UI.Page.DND = new Plex.Com.DND();

Plex.UI.Page.DND.handler.noTarget=function(clone,object)
{
	object.style.top=clone.style.top;
	object.style.left=clone.style.left;
};

Plex.UI.Page.DND.handler.onDragStart=function(object)
{
	object.style.zIndex=(Plex.UI.zIndex++)+10000;
};
	

Plex.UI.Page.Popup = function()
{
	var self = this;
	this.popup=1;
	
	this.onOpen = function(){};
	this.onClose = function(){};
	this.onMove = function(){};
	this.onResize = function(){};

	//Create Elements
	this.el = {};
	this.el.table = new Element('table',{
		'class':'Popup',
		'cellspacing':0,
		'cellpadding':0,
		'border':0,
		'styles':{
			'z-Index':(Plex.UI.zIndex++)
		},
		'events':{
			'click':function(){
				self.el.table.set({
					'styles':{
						'z-Index':Plex.UI.zIndex++
					}
				})
			}
		}
	})

	this.el.topRow = new Element('tr').injectInside(this.el.table);
	this.el.midRow = new Element('tr').injectInside(this.el.table);
	this.el.botRow = new Element('tr').injectInside(this.el.table);

	this.el.topLeftCol = new Element('td',{'class':'topLeft'}).injectInside(this.el.topRow);
	this.el.topMidCol = new Element('td',{'class':'topCenter'}).injectInside(this.el.topRow);
	this.el.topRightCol = new Element('td',{'class':'topRight'}).injectInside(this.el.topRow);

	this.el.midLeftCol = new Element('td',{'class':'midLeft'}).injectInside(this.el.midRow);
	this.el.midCenterCol = new Element('td',{'class':'midCenter'}).injectInside(this.el.midRow);
	this.el.midRightCol = new Element('td',{'class':'midRight'}).injectInside(this.el.midRow);

	this.el.botLeftCol = new Element('td',{'class':'botLeft'}).injectInside(this.el.botRow);
	this.el.botCenterCol = new Element('td',{'class':'botCenter'}).injectInside(this.el.botRow);
	this.el.botRightCol = new Element('td',{'class':'botRight'}).injectInside(this.el.botRow);


	this.el.closeButton = new Element('div',{
		'class':'closeButton',
		'events':{
			'click':function(){
				self.close();
			}
		}
	}).injectInside(this.el.midCenterCol);
	this.el.headerDiv = new Element('div',{'class':'header'}).injectInside(this.el.midCenterCol);
	this.el.bodyDiv = new Element('div',{'class':'body'}).injectInside(this.el.midCenterCol);
	this.el.footerDiv = new Element('div',{'class':'footer'}).injectInside(this.el.midCenterCol);

	this.setTitle = function(newTitle)
	{
		self.el.headerDiv.setText(newTitle);
	}
	
	this.moveTo = function(x,y)
	{
		self.el.table.style.left=x;
		self.el.table.style.top=y;
	}
	
	this.resizeTo = function(w,h)
	{
		
	}
	
	this.open = function()
	{
		self.el.table.injectInside(document.body);
		self.el.table.style.zIndex=Plex.UI.zIndex++;
		self.onOpen();
	}
	
	this.close = function()
	{
		Summit.S$.remove(self.el.table)
		self.onClose();
	}

	this.closeButton = new Plex.UI.Button.Small_Text();
	this.closeButton.setTitle('Close');
	this.closeButton.onClick=this.close;
	this.closeButton.object.injectInside(this.el.footerDiv);
	
	Plex.UI.Page.DND.addObject(self.el.table);
}